package com.zhidisoft.crm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zhidisoft.crm.dao.ISysRoleMapper;
import com.zhidisoft.crm.entity.SysRole;
import com.zhidisoft.crm.service.ISysRoleService;
import com.zhidisoft.crm.vo.PageVo;
import com.zhidisoft.crm.vo.SysRoleVo;

@Service
@Transactional
public class SysRoleImpl implements ISysRoleService{
	
	@Autowired
	ISysRoleMapper roleMapper;
	/**
	 * 添加角色
	 */
	@Override
	public void save(SysRole role) {
		roleMapper.save(role);
	}
	/**
	 * 根据用户名查询角色
	 */
	@Override
	public SysRole findByuser(String username) {
		return roleMapper.findByuser(username);
	}
	/**
	 * 分页查询角色
	 */
	@Override
	public PageVo findPage(Integer pageNum, Integer pageSize) {
		PageVo pageVo=new PageVo();
		pageVo.setPageNum(pageNum);
		pageVo.setPageSize(pageSize);
		int beginIndex = (pageNum - 1) * pageSize;
		int endIndex = beginIndex + pageSize;
		pageVo.setList(roleMapper.pageList(beginIndex, endIndex));
		pageVo.setList(roleMapper.pageList((pageNum-1)*pageSize, pageSize));
		pageVo.setTotalCount(roleMapper.totalCount().intValue());
		return pageVo;
	}
	/**
	 * 获取角色总条数
	 */
	@Override
	public Long totalCount() {
		return roleMapper.totalCount();
	}
	/**
	 * 根据id删除角色
	 */
	@Override
	public void deleteById(String id) {
		roleMapper.deleteById(id);
	}
	/**
	 * 根据id查询角色
	 */
	@Override
	public SysRole selectById(String id) {
		return roleMapper.selectById(id);
	}
	@Override
	public void update(SysRole sysRole) {
		roleMapper.update(sysRole);
	}
	@Override
	public List<SysRole> selectAll() {
		return roleMapper.selectAll();
	}
	
	
}
